#include "lecturedialog.h"
#include "lectlabel.h"
#include "connexion.h"
#include "icore.h"

#include <QtGui>
#include <QtCore>
#include <QtSql>

QString g_pathabsolu ;
int g_increment = 0 ;
using namespace Common;
void myMessageOutput(QtMsgType type, const char *msg)
 {
     QFile file(qApp->applicationDirPath ()+"/errorLog.txt");
     file.open(QIODevice::ReadWrite|QIODevice::Append);
     QTextStream s(&file);
     switch (type) {
     case QtDebugMsg:
         s << "Debug: " << QString(msg) << "\n";
         break;
     case QtWarningMsg:
         s << "Warning: " << QString(msg) << "\n";
         break;
     case QtCriticalMsg:
         s << "Critical: " << QString(msg) << "\n";
         break;
     case QtFatalMsg:
         s << "Fatal: " << QString(msg) << "\n";
         abort();
     }

     file.close();
 }
 
int main(int argc,char *argv[])
{
  g_increment = 0;
  g_pathabsolu = "" ;
  QString str = "";
  qInstallMsgHandler(myMessageOutput);
  QApplication application(argc,argv);
  QFile f(application.applicationDirPath ()+"/errorLog.txt");
  f.remove();
  QStringList arguments;
  arguments = application.arguments();

  if(arguments.size()==0){
      QMessageBox::critical(0,QObject::tr("fatal"),QObject::trUtf8("le path ne peut être trouvé"),QMessageBox::Abort);
  }
  QFileInfo pathinfo(arguments[0]);
  if(pathinfo.exists()){//indispensable car le path est long à trouver et ça plante pour ce logiciel !
      str = pathinfo.absolutePath();
      ::g_pathabsolu = str;}

  if(!ICore::instance()->initialize()){
      QMessageBox::critical(0,QObject::tr("fatal"),QObject::trUtf8("connexion base de donnée impossible"),QMessageBox::Abort);
      return false;
  }
  Lecturalarme *dialogue = new Lecturalarme;
                dialogue-> show();

  return application.exec();
}
